package com.kfm.exec02;

import java.util.*;

public class Room {

    public List list = new ArrayList<>();

    Player p1 = new Player();
    Player p2 = new Player();
    Player p3 = new Player();

    List bottom;

    /**
     * 开始游戏
     */
    public void start() {
        initCards();
        shuffle();
    }

    public void initCards() {
        // 生成 54个 Card 对象
        String[] colors = {"♠️", "♥️", "♣️", "♦️"};
        String[] codes = {"A", "2", "3", "4", "5", "6", "7", "8", "9",
                "10", "J", "Q", "K"};
        for (int i = 0; i < 4; i++) {
            String color = colors[i];
            for (int j = 0; j < 13; j++) {
                String code = codes[j];
                Card card = new Card(code, color, j + 1);
                list.add(card);
            }
        }
        list.add(new Card("", "🤡", 14));
        list.add(new Card("", "🃏", 15));
    }

    public void shuffle() {
        // 打乱牌序列
        Collections.shuffle(list);
        System.out.println(list.size());
    }

    public void dealCard() {
        // for (int i = 0; i < 17; i ++) {
        //     p1.getList().add(list.remove(i));
        //     p2.getList().add(list.remove(i));
        //     p3.getList().add(list.remove(i));
        // }
        p1.setList(list.subList(0, 17));
        p2.setList(list.subList(17, 34));
        p3.setList(list.subList(34, 51));
        bottom = list.subList(51, 54);
    }

    public void stroke() {
        Comparator<Object> comparator = new Comparator<>() {
            @Override
            public int compare(Object o1, Object o2) {
                Card c1 = (Card) o1;
                Card c2 = (Card) o2;
                return c1.getPoint() - c2.getPoint();
            }
        };
        Collections.sort(p1.getList(), comparator);
        Collections.sort(p2.getList(), comparator);
        Collections.sort(p3.getList(), comparator);
    }

    public void watch() {
        System.out.println(p1.getList().size());
        System.out.println(p2.getList());
        System.out.println(p3.getList());
        System.out.println(bottom);
    }

}

class Test {

    public static void main(String[] args) {
        Room room = new Room();
        room.list.get(0);
        room.start();
        room.dealCard();
        room.stroke();
        room.watch();
        List list = new ArrayList<>();
        list.add(1);
        list.add("11");
        list.add(new Card("", "", 1));
        ((Card)list.get(2)).getPoint();
        List<Card> cards = new ArrayList<>(); // list 集合中存储的 是Card对象
        // cards.add(1);
        // cards.add("1");
        cards.add(new Card("", "", 1));
        // 当给设置了泛型的集合中存储元素 会进行类型检查 获取元素会进行类型推断。
        Integer point = cards.get(0).getPoint();
        Iterator<Card> cardIterator = cards.iterator();
        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        // list1.add(1.1);

    }
}